package com.kukudexin.lockThread;

import java.util.concurrent.locks.*;

/**
 * @author: 酷酷的鑫
 * @description:
 */
public class LockThread11 {
    private Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();

    public static void main(String[] args) {
        LockThread11 thread11 = new LockThread11();
        thread11.cal();
        try {
            Thread.sleep(3000);
        } catch (Exception e) {

        }
        thread11.signal();

    }
    public void signal() {
        try {
            lock.lock();
//            this.notify();
            condition.signal();
        } catch (Exception e) {

        } finally {
            lock.unlock();
        }
    }

    public void cal() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 主动释放锁 同时当前线程变为阻塞状态
                try {
                    lock.lock();
                    System.out.println("1");
                    condition.await();
                    System.out.println("2");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            }
        }).start();
    }
}
